import pandas as pd
import matplotlib.pyplot as plt
import seaborn as sns
População
pop = pd.read_csv('https://raw.githubusercontent.com/voigtjessica/pop_brasil_2019/master/pop_brasil_2019.csv', index_col=0)
pop.head()
| codigo_ibge | municipio | unidade_federativa | populacao | is_capital | |
|---|---|---|---|---|---|
| posicao | |||||
| 1 | 3550308 | São Paulo | São Paulo | 12252023 | True |
| 2 | 3304557 | Rio de Janeiro | Rio de Janeiro | 6718903 | True |
| 3 | 5300108 | Brasília | Distrito Federal | 3015268 | True |
| 4 | 2927408 | Salvador | Bahia | 2872347 | True |
| 5 | 2304400 | Fortaleza | Ceará | 2669342 | True |
Dados suicídios
df = pd.read_csv('datasus_suicidio_2014_2018.csv', encoding='latin1', on_bad_lines='skip')
df.head()
| estado | ano | CIRCOBITO | DTOBITO | DTNASC | SEXO | RACACOR | ESTCIV | ESC | OCUP | CODMUNRES | LOCOCOR | ASSISTMED | CAUSABAS | CAUSABAS_O | idade | mes | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AC | 2014 | Suicidio | 02-01-14 | 02-07-77 | Masculino | Preta | Casado | 4 a 7 anos | ATLETA PROFISSIONAL DE FUTEBOL | Rio Branco | Domicílio | Não | X700 | X700 | 37.0 | 1 |
| 1 | AC | 2014 | Suicidio | 23-01-14 | 30-07-66 | Masculino | Branca | União consensual | 12 e mais | MEDICO GINECOLOGISTA E OBSTETRA | Rio Branco | Domicílio | Não | X800 | X800 | 48.0 | 1 |
| 2 | AC | 2014 | Suicidio | 31-01-14 | 28-07-43 | Masculino | Branca | NaN | NaN | 0 | Rio Branco | Domicílio | Não | X700 | X700 | 71.0 | 1 |
| 3 | AC | 2014 | Suicidio | 05-02-14 | 04-07-99 | Masculino | Branca | Solteiro | 4 a 7 anos | ESTUDANTE | Epitaciolândia | Outros | Não | X700 | X700 | 15.0 | 2 |
| 4 | AC | 2014 | Suicidio | 06-02-14 | 02-05-72 | Masculino | Branca | NaN | NaN | 0 | Rio Branco | Outros | Não | X700 | X700 | 42.0 | 2 |
Malha geográfica
from geobr import read_municipality
# Read all municipalities of given state at a given year
mun = read_municipality(code_muni="all", year=2020)
mun.head()
/home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:93: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry. aout[:] = out
| code_muni | name_muni | code_state | abbrev_state | name_state | code_region | name_region | geometry | |
|---|---|---|---|---|---|---|---|---|
| 0 | 1100015.0 | Alta Floresta D'oeste | 11.0 | RO | Rondônia | 1.0 | Norte | MULTIPOLYGON (((-62.19465 -11.82746, -62.18945... |
| 1 | 1100023.0 | Ariquemes | 11.0 | RO | Rondônia | 1.0 | Norte | MULTIPOLYGON (((-62.53648 -9.73222, -62.52765 ... |
| 2 | 1100031.0 | Cabixi | 11.0 | RO | Rondônia | 1.0 | Norte | MULTIPOLYGON (((-60.37119 -13.36655, -60.37661... |
| 3 | 1100049.0 | Cacoal | 11.0 | RO | Rondônia | 1.0 | Norte | MULTIPOLYGON (((-61.00080 -11.29737, -61.00103... |
| 4 | 1100056.0 | Cerejeiras | 11.0 | RO | Rondônia | 1.0 | Norte | MULTIPOLYGON (((-61.49976 -13.00525, -61.49426... |
Base de dados com os códigos de Cid10
cid = pd.read_csv('https://raw.githubusercontent.com/ericgrossi/CID10xml/master/CID10.csv', sep='\t', index_col=0)
cid
| Capítulo | A00-B99 Capítulo I | I | Certas doenças infecciosas e parasitárias | Certas doenças infecciosas e parasitárias.1 | Certas doenças infecciosas e parasitárias.2 | |
|---|---|---|---|---|---|---|
| 1 | ||||||
| 2 | Grupo | A00- A09 | I | Certas doenças infecciosas e parasitárias | Doenças infecciosas intestinais | Doenças infecciosas intestinais |
| 3 | Categoria | A00 | I | Certas doenças infecciosas e parasitárias | Doenças infecciosas intestinais | Cólera |
| 4 | Subcategoria | A000 | I | Certas doenças infecciosas e parasitárias | Doenças infecciosas intestinais | Cólera devido ao Vibrio cholerae 01, biovar ch... |
| 5 | Subcategoria | A001 | I | Certas doenças infecciosas e parasitárias | Doenças infecciosas intestinais | Cólera devido ao Vibrio cholerae 01, biovar eltor |
| 6 | Subcategoria | A009 | I | Certas doenças infecciosas e parasitárias | Doenças infecciosas intestinais | Cólera não especificada |
| ... | ... | ... | ... | ... | ... | ... |
| 12487 | Subcategoria | Z99.2 | XXI | Fatores que influenciam o estado de saúde e o ... | Pessoas com riscos potenciais à saúde relacion... | Dependência de diálise renal |
| 12488 | Subcategoria | Z99.3 | XXI | Fatores que influenciam o estado de saúde e o ... | Pessoas com riscos potenciais à saúde relacion... | Dependência de cadeira de rodas |
| 12489 | Subcategoria | Z99.4 | XXI | Fatores que influenciam o estado de saúde e o ... | Pessoas com riscos potenciais à saúde relacion... | Dependência em coração artificial |
| 12490 | Subcategoria | Z99.8 | XXI | Fatores que influenciam o estado de saúde e o ... | Pessoas com riscos potenciais à saúde relacion... | Dependência de outras máquinas e dispositivos ... |
| 12491 | Subcategoria | Z99.9 | XXI | Fatores que influenciam o estado de saúde e o ... | Pessoas com riscos potenciais à saúde relacion... | Dependência de máquina e dispositivo habilitad... |
12501 rows × 6 columns
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 57785 entries, 0 to 57784 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 estado 57785 non-null object 1 ano 57785 non-null int64 2 CIRCOBITO 55775 non-null object 3 DTOBITO 57785 non-null object 4 DTNASC 57558 non-null object 5 SEXO 57770 non-null object 6 RACACOR 56455 non-null object 7 ESTCIV 53485 non-null object 8 ESC 44436 non-null object 9 OCUP 57785 non-null object 10 CODMUNRES 57785 non-null object 11 LOCOCOR 57614 non-null object 12 ASSISTMED 40248 non-null object 13 CAUSABAS 57785 non-null object 14 CAUSABAS_O 57696 non-null object 15 idade 57558 non-null float64 16 mes 57785 non-null int64 dtypes: float64(1), int64(2), object(14) memory usage: 7.5+ MB
definindo idade como coluna de números inteiros; e para fins de análise, ano e mês serão string
df = df.fillna(0).astype({"idade":"int", "ano": "str", "mes":"str"})
Transformando a coluna data, em forma de objeto, para o formato data
df['DTOBITO']= pd.to_datetime(df['DTOBITO'])
df['DTNASC']= pd.to_datetime(df['DTNASC'])
df.info()
<class 'pandas.core.frame.DataFrame'> RangeIndex: 57785 entries, 0 to 57784 Data columns (total 17 columns): # Column Non-Null Count Dtype --- ------ -------------- ----- 0 estado 57785 non-null object 1 ano 57785 non-null object 2 CIRCOBITO 57785 non-null object 3 DTOBITO 57785 non-null datetime64[ns] 4 DTNASC 57785 non-null datetime64[ns] 5 SEXO 57785 non-null object 6 RACACOR 57785 non-null object 7 ESTCIV 57785 non-null object 8 ESC 57785 non-null object 9 OCUP 57785 non-null object 10 CODMUNRES 57785 non-null object 11 LOCOCOR 57785 non-null object 12 ASSISTMED 57785 non-null object 13 CAUSABAS 57785 non-null object 14 CAUSABAS_O 57785 non-null object 15 idade 57785 non-null int64 16 mes 57785 non-null object dtypes: datetime64[ns](2), int64(1), object(14) memory usage: 7.5+ MB
df['OCUP'].value_counts()
0 12353
APOSENTADO/PENSIONISTA 4251
ESTUDANTE 4191
DONA DE CASA 2995
TRABALHADOR AGROPECUARIO EM GERAL 2877
...
TECNICO DE ENFERMAGEM DE TERAPIA INTENSIVA 1
DECORADOR DE INTERIORES DE NIVEL SUPERIOR 1
ENOLOGO 1
APICULTOR 1
GERENTE DE PESQUISA E DESENVOLVIMENTO (P&D) 1
Name: OCUP, Length: 1068, dtype: int64
df['idade'].value_counts()
33 1262
30 1256
35 1247
31 1246
39 1230
...
5 1
112 1
103 1
99 1
102 1
Name: idade, Length: 106, dtype: int64
df.groupby(['estado']).agg({'idade' : 'mean'})
| idade | |
|---|---|
| estado | |
| AC | 33.127820 |
| AL | 39.335616 |
| AM | 31.426667 |
| AP | 31.298246 |
| BA | 43.110520 |
| CE | 41.919162 |
| DF | 38.900901 |
| ES | 43.286885 |
| GO | 41.585418 |
| MA | 39.277322 |
| MG | 43.076622 |
| MS | 36.676647 |
| MT | 40.402235 |
| PA | 35.326165 |
| PB | 43.692455 |
| PE | 42.382337 |
| PI | 41.822283 |
| PR | 42.918351 |
| RJ | 43.921198 |
| RN | 43.868331 |
| RO | 37.922053 |
| RR | 30.464789 |
| RS | 48.323416 |
| SC | 45.362265 |
| SE | 40.723967 |
| SP | 41.763921 |
| TO | 40.651252 |
df['estado'].value_counts()
SP 11098 MG 6891 RS 5949 PR 3711 SC 3249 CE 3006 RJ 2906 BA 2633 GO 2318 PE 1891 MA 1464 PI 1463 PA 1395 MS 1169 AM 1125 PB 1047 ES 976 MT 895 RN 881 DF 777 SE 605 AL 584 RO 526 TO 519 AC 266 AP 228 RR 213 Name: estado, dtype: int64
estado_ocup = df.groupby(['estado','OCUP']).size().to_frame(name = 'Occurrence').reset_index()
estado_ocup.head()
| estado | OCUP | Occurrence | |
|---|---|---|---|
| 0 | AC | 0 | 111 |
| 1 | AC | ACOUGUEIRO | 1 |
| 2 | AC | ADMINISTRADOR | 1 |
| 3 | AC | AGENTE COMUNITARIO DE SAUDE | 1 |
| 4 | AC | APOSENTADO/PENSIONISTA | 12 |
import plotly.graph_objects as go
import plotly.express as px
fig = px.scatter(estado_ocup, x="estado", y="Occurrence", color="OCUP", symbol="OCUP")
fig.update_traces(marker_size=10)
fig.show()
NOTA:
Percbe-se que a maioria dos casos estão notificados com ocupação = 0 , ou seja, com a ausência da informação. Seja pelo não preenchimento correto dos dados ou por não saber de fato a ocupação do indivíduo.
Em alguns estados, como SP e RS, nota-se um elevado número de ocorrências relacionadas à Aposentados/Pensionistas;
Em SP, também é perceptível o elevado número de ocorrências com Estudantes e Donas de casa
Já em regiões mais afastadas dos grandes centros do Sudeste, temos como a Bahia e seu estado vizinho, MG, um alto número relacionado à Trabalhadores da agropecuária em geral
União da tabela df (dados suicídio) com a malha geografica dos municipios (mun)
df = pd.merge(df, mun, left_on=['estado','CODMUNRES'], right_on=['abbrev_state', 'name_muni'], how='left')
df.head()
| estado | ano | CIRCOBITO | DTOBITO | DTNASC | SEXO | RACACOR | ESTCIV | ESC | OCUP | ... | idade | mes | code_muni | name_muni | code_state | abbrev_state | name_state | code_region | name_region | geometry | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AC | 2014 | Suicidio | 2014-02-01 | 1977-02-07 | Masculino | Preta | Casado | 4 a 7 anos | ATLETA PROFISSIONAL DE FUTEBOL | ... | 37 | 1 | 1200401.0 | Rio Branco | 12.0 | AC | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... |
| 1 | AC | 2014 | Suicidio | 2014-01-23 | 2066-07-30 | Masculino | Branca | União consensual | 12 e mais | MEDICO GINECOLOGISTA E OBSTETRA | ... | 48 | 1 | 1200401.0 | Rio Branco | 12.0 | AC | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... |
| 2 | AC | 2014 | Suicidio | 2014-01-31 | 2043-07-28 | Masculino | Branca | 0 | 0 | 0 | ... | 71 | 1 | 1200401.0 | Rio Branco | 12.0 | AC | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... |
| 3 | AC | 2014 | Suicidio | 2014-05-02 | 1999-04-07 | Masculino | Branca | Solteiro | 4 a 7 anos | ESTUDANTE | ... | 15 | 2 | 1200252.0 | Epitaciolândia | 12.0 | AC | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.64480 -10.61638, -68.64306... |
| 4 | AC | 2014 | Suicidio | 2014-06-02 | 2072-02-05 | Masculino | Branca | 0 | 0 | 0 | ... | 42 | 2 | 1200401.0 | Rio Branco | 12.0 | AC | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... |
5 rows × 25 columns
União da tabela df (suicídio) com a tabela cid10 (codigo com a descrição do tipo de suicídio)
diminuindo a coluna CAUSABAS de X700 para X70, a fim de haver compatibilidade com a tabela cid
df['CAUSABAS'] = df['CAUSABAS'].str.slice(stop=3)
df = pd.merge(df, cid, left_on='CAUSABAS', right_on='A00-B99 Capítulo I', how='left')
df.head()
| estado | ano | CIRCOBITO | DTOBITO | DTNASC | SEXO | RACACOR | ESTCIV | ESC | OCUP | ... | name_state | code_region | name_region | geometry | Capítulo | A00-B99 Capítulo I | I | Certas doenças infecciosas e parasitárias | Certas doenças infecciosas e parasitárias.1 | Certas doenças infecciosas e parasitárias.2 | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AC | 2014 | Suicidio | 2014-02-01 | 1977-02-07 | Masculino | Preta | Casado | 4 a 7 anos | ATLETA PROFISSIONAL DE FUTEBOL | ... | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... | Categoria | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... |
| 1 | AC | 2014 | Suicidio | 2014-01-23 | 2066-07-30 | Masculino | Branca | União consensual | 12 e mais | MEDICO GINECOLOGISTA E OBSTETRA | ... | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... | Categoria | X80 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional saltando de um lugar... |
| 2 | AC | 2014 | Suicidio | 2014-01-31 | 2043-07-28 | Masculino | Branca | 0 | 0 | 0 | ... | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... | Categoria | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... |
| 3 | AC | 2014 | Suicidio | 2014-05-02 | 1999-04-07 | Masculino | Branca | Solteiro | 4 a 7 anos | ESTUDANTE | ... | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.64480 -10.61638, -68.64306... | Categoria | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... |
| 4 | AC | 2014 | Suicidio | 2014-06-02 | 2072-02-05 | Masculino | Branca | 0 | 0 | 0 | ... | Acre | 1.0 | Norte | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... | Categoria | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... |
5 rows × 31 columns
Unindo as tabelas dados de suicidio (df) à pop (população por municipio)
df.columns
Index(['estado', 'ano', 'CIRCOBITO', 'DTOBITO', 'DTNASC', 'SEXO', 'RACACOR',
'ESTCIV', 'ESC', 'OCUP', 'CODMUNRES', 'LOCOCOR', 'ASSISTMED',
'CAUSABAS', 'CAUSABAS_O', 'idade', 'mes', 'code_muni', 'name_muni',
'code_state', 'abbrev_state', 'name_state', 'code_region',
'name_region', 'geometry', 'Capítulo', 'A00-B99 Capítulo I', 'I',
'Certas doenças infecciosas e parasitárias',
'Certas doenças infecciosas e parasitárias.1',
'Certas doenças infecciosas e parasitárias.2'],
dtype='object')
pop.columns
Index(['codigo_ibge', 'municipio', 'unidade_federativa', 'populacao',
'is_capital'],
dtype='object')
df['code_muni'] = df['code_muni'].fillna(0).astype(int)
df = pd.merge(df, pop, left_on='code_muni', right_on='codigo_ibge', how='left')
df.head()
| estado | ano | CIRCOBITO | DTOBITO | DTNASC | SEXO | RACACOR | ESTCIV | ESC | OCUP | ... | A00-B99 Capítulo I | I | Certas doenças infecciosas e parasitárias | Certas doenças infecciosas e parasitárias.1 | Certas doenças infecciosas e parasitárias.2 | codigo_ibge | municipio | unidade_federativa | populacao | is_capital | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | AC | 2014 | Suicidio | 2014-02-01 | 1977-02-07 | Masculino | Preta | Casado | 4 a 7 anos | ATLETA PROFISSIONAL DE FUTEBOL | ... | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... | 1200401.0 | Rio Branco | Acre | 407319.0 | True |
| 1 | AC | 2014 | Suicidio | 2014-01-23 | 2066-07-30 | Masculino | Branca | União consensual | 12 e mais | MEDICO GINECOLOGISTA E OBSTETRA | ... | X80 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional saltando de um lugar... | 1200401.0 | Rio Branco | Acre | 407319.0 | True |
| 2 | AC | 2014 | Suicidio | 2014-01-31 | 2043-07-28 | Masculino | Branca | 0 | 0 | 0 | ... | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... | 1200401.0 | Rio Branco | Acre | 407319.0 | True |
| 3 | AC | 2014 | Suicidio | 2014-05-02 | 1999-04-07 | Masculino | Branca | Solteiro | 4 a 7 anos | ESTUDANTE | ... | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... | 1200252.0 | Epitaciolândia | Acre | 18411.0 | False |
| 4 | AC | 2014 | Suicidio | 2014-06-02 | 2072-02-05 | Masculino | Branca | 0 | 0 | 0 | ... | X70 | XX | Causas externas de morbidade e mortalidade | Automutilação intencional | Automutilação intencional por enforcamento, es... | 1200401.0 | Rio Branco | Acre | 407319.0 | True |
5 rows × 36 columns
#df = pd.merge(df, pop, left_on=['name_state','name_muni'], right_on=['unidade_federativa', 'municipio'], how='left')
Análise Exploratória (contagens)
df['RACACOR'].value_counts()
Branca 28662 Parda 23876 Preta 3022 0 1330 Indígena 655 Amarela 240 Name: RACACOR, dtype: int64
df['ESTCIV'].value_counts()
Solteiro 29010 Casado 15159 0 4300 Separado judicialmente 4078 União consensual 3093 Viúvo 2145 Name: ESTCIV, dtype: int64
Gráficos de número de suicídios por ano (2014 - 2018)
obt_ano = df['ano'].value_counts().to_frame(name = 'Occurrence').reset_index()
obt_ano
| index | Occurrence | |
|---|---|---|
| 0 | 2018 | 12584 |
| 1 | 2017 | 12322 |
| 2 | 2016 | 11299 |
| 3 | 2015 | 11048 |
| 4 | 2014 | 10532 |
plt.figure(figsize=(12,8))
a = plt.plot(df['ano'].value_counts(sort=False) , color='Red')
plt.title('Número de Suicídios por Ano no Brasil (2014 - 2018)')
plt.xlabel('Ano')
plt.ylabel('Número de Suicídios')
plt.show()
NOTA:
Gráfico com número de suicídios por estado da federação e sexo
#dimensões do gráfico
plt.figure(figsize=(15, 7), dpi=80)
#cores das barras
colors=['#0A2463', '#FF3CC7', '#FB3640']
#gráfico
sns.countplot(x ='estado', hue = "SEXO", data = df, palette=colors)
#títulos e labels
plt.title('Número de Suicídios por Estado Brasileiro e Sexo (2014 - 2018)')
plt.xlabel('Estado')
plt.ylabel('Número de Suicídios')
#rotação das labels do eixo x
plt.xticks(rotation=45)
plt.show()
NOTA:
É evidente que os casos de suicídio no Brasil compreendem, em sua maioria, homens.
Além disso o maior número absoluto de casos, concentram-se em SP, seguido de MG, uma possibilidade é que são estados com elevadas populações.
Gráfico de Pizza (Pie Chart) com a cor da pele dos indivíduos que cometeram suicídio
#dimensões do gráfico
plt.figure(figsize=(5,5))
#gráfico com cores e apresentando porcentagem
df['RACACOR'].value_counts(normalize=True).plot(kind='pie', explode=(0, 0,0,0 ,0, 0), shadow=True, startangle=0, colors=["#EA638C","#235789", "#C1292E", "#F1D302", "#161925", "coral", "palegreen"], autopct='%1.1f%%')
centre_circle = plt.Circle((0,0),0.70,fc='white')
fig = plt.gcf()
fig.gca().add_artist(centre_circle)
plt.tight_layout()
#título
plt.title('Cor da Pele')
plt.ylabel("")
plt.show()
NOTA:
Contagem com valores absolutos da cor da pele
df['RACACOR'].value_counts()
Branca 28662 Parda 23876 Preta 3022 0 1330 Indígena 655 Amarela 240 Name: RACACOR, dtype: int64
Heatmap relacionando estado civil e região do país
df['ESTCIV'] = df['ESTCIV'].replace(['0'],'Não informado')
a = pd.crosstab(index=df['ESTCIV'], columns=df['name_region'], normalize='index')
plt.figure(figsize=(16,8))
sns.heatmap(a, annot=True, cmap="BuPu")
<AxesSubplot:xlabel='name_region', ylabel='ESTCIV'>
NOTA:
df['Certas doenças infecciosas e parasitárias.2'].value_counts()
Automutilação intencional por enforcamento, estrangulamento e sufocação 39590
Automutilação intencional por outras descargas de armas de fogo não especificadas 3133
Automutilação intencional saltando de um lugar alto 2299
Auto-Intoxicação intencional por e exposição a pesticidas 2219
Automutilação intencional por descarga de arma 1323
...
Outras doenças cardíacas reumáticas 1
Leiomioma do útero 1
Assalto por objeto contundente 1
Hemorragia intracerebral 1
Exposição a outros tipos de fumaça, fogo e chamas 1
Name: Certas doenças infecciosas e parasitárias.2, Length: 92, dtype: int64
Criando um novo dataframe relacionando o tipo de suicídio e a região do país
regiao_causa = df.groupby(['name_region','Certas doenças infecciosas e parasitárias.2']).size().to_frame(name = 'Occurrence').reset_index()
regiao_causa.head()
| name_region | Certas doenças infecciosas e parasitárias.2 | Occurrence | |
|---|---|---|---|
| 0 | Centro Oeste | Afogamento e submersão, intenção indeterminada | 1 |
| 1 | Centro Oeste | Assalto por enforcamento, estrangulamento e su... | 1 |
| 2 | Centro Oeste | Assalto por objeto pontiagudo | 1 |
| 3 | Centro Oeste | Assalto por outra descarga de armas de fogo nã... | 3 |
| 4 | Centro Oeste | Auto envenenamento intencional por e exposição... | 3 |
fig = px.scatter(regiao_causa, x="name_region", y="Occurrence", color="Certas doenças infecciosas e parasitárias.2", symbol="Certas doenças infecciosas e parasitárias.2")
fig.update_layout(legend=dict(title_font_family="Times New Roman",
font=dict(size= 9)))
fig.update_traces(marker_size=10)
fig.show()
NOTA:
Há, como causa do suicídio, um predomínio do enforcamento em todas as regiões do país.
Destaca-se no Sul do país o uso de arma de fogo para alcançar a automultilação
Já no Sudeste, há o salto intencional de lugares altos. Fator interessante, se considerarmos que é a região do país, possivelmente, com o maior número de prédios e edifícios altos.
Já no Nordeste, é frequente o suicídio mediado por auto-intoxicação por exposição à pesticida. Dado o cárater mais voltado à agropecuária e rural da maior parte dessa região do Brasil.
Média de idade por tipo de suicídio
df.groupby(['Certas doenças infecciosas e parasitárias.2']).agg({'idade' : 'mean'})
| idade | |
|---|---|
| Certas doenças infecciosas e parasitárias.2 | |
| Afogamento e submersão após queda em água natural | 86.000000 |
| Afogamento e submersão em águas naturais | 30.666667 |
| Afogamento e submersão não especificados | 48.333333 |
| Afogamento e submersão, intenção indeterminada | 25.500000 |
| Agressão sexual por força corporal | 16.000000 |
| ... | ... |
| Transtornos mentais e comportamentais associados ao puerpério, não classificados em outra parte | 40.000000 |
| Transtornos mentais e comportamentais devidos ao uso de múltiplas drogas e uso de outras substâncias psicoativas | 44.000000 |
| Transtornos mentais e comportamentais devidos ao uso de sedativos ou hipnóticos | 34.000000 |
| Transtornos mentais e comportamentais devidos ao uso de álcool | 43.333333 |
| Vítima de avalanche, deslizamento de terra e outros movimentos de terra | 78.000000 |
92 rows × 1 columns
transformando a coluna população em numero inteiro
df['populacao'] = df['populacao'].fillna(0).astype(int)
casos_municipio = df.groupby(['codigo_ibge','estado', 'municipio', 'populacao']).size().to_frame(name = 'Casos').reset_index()
casos_municipio.head()
| codigo_ibge | estado | municipio | populacao | Casos | |
|---|---|---|---|---|---|
| 0 | 1100023.0 | RO | Ariquemes | 107863 | 24 |
| 1 | 1100031.0 | RO | Cabixi | 5312 | 4 |
| 2 | 1100049.0 | RO | Cacoal | 85359 | 33 |
| 3 | 1100056.0 | RO | Cerejeiras | 16323 | 6 |
| 4 | 1100080.0 | RO | Costa Marques | 18331 | 4 |
Calculando a prevalencia (numero de casos no municipio / população)
casos_municipio['prevalencia'] = casos_municipio['Casos']/casos_municipio['populacao'] *100000
Pegando dados agrupados: estado, municipio e malha geografica e retirando duplicatas
malha_geografica = df[['estado','municipio','geometry']].drop_duplicates()
malha_geografica.head()
/home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/array.py:125: ShapelyDeprecationWarning: __len__ for multi-part geometries is deprecated and will be removed in Shapely 2.0. Check the length of the `geoms` property instead to get the number of parts of a multi-part geometry.
| estado | municipio | geometry | |
|---|---|---|---|
| 0 | AC | Rio Branco | MULTIPOLYGON (((-68.58415 -9.53920, -68.51407 ... |
| 3 | AC | Epitaciolândia | MULTIPOLYGON (((-68.64480 -10.61638, -68.64306... |
| 6 | AC | Senador Guiomard | MULTIPOLYGON (((-67.13456 -9.67824, -67.13731 ... |
| 8 | AC | NaN | None |
| 9 | AC | Feijó | MULTIPOLYGON (((-70.05145 -7.84816, -69.44432 ... |
União ao dataframe com o numero de casos
casos_municipio = pd.merge(casos_municipio, malha_geografica)
casos_municipio.head()
| codigo_ibge | estado | municipio | populacao | Casos | prevalencia | geometry | |
|---|---|---|---|---|---|---|---|
| 0 | 1100023.0 | RO | Ariquemes | 107863 | 24 | 22.250447 | MULTIPOLYGON (((-62.53648 -9.73222, -62.52765 ... |
| 1 | 1100031.0 | RO | Cabixi | 5312 | 4 | 75.301205 | MULTIPOLYGON (((-60.37119 -13.36655, -60.37661... |
| 2 | 1100049.0 | RO | Cacoal | 85359 | 33 | 38.660247 | MULTIPOLYGON (((-61.00080 -11.29737, -61.00103... |
| 3 | 1100056.0 | RO | Cerejeiras | 16323 | 6 | 36.757949 | MULTIPOLYGON (((-61.49976 -13.00525, -61.49426... |
| 4 | 1100080.0 | RO | Costa Marques | 18331 | 4 | 21.820959 | MULTIPOLYGON (((-63.71199 -11.65013, -63.70413... |
Plotando mapa do Brasil com a prevalencia
import geopandas as gpd
gdf= gpd.GeoDataFrame(casos_municipio.set_index('codigo_ibge')[['prevalencia', 'geometry']])
gdf
| prevalencia | geometry | |
|---|---|---|
| codigo_ibge | ||
| 1100023.0 | 22.250447 | MULTIPOLYGON (((-62.53648 -9.73222, -62.52765 ... |
| 1100031.0 | 75.301205 | MULTIPOLYGON (((-60.37119 -13.36655, -60.37661... |
| 1100049.0 | 38.660247 | MULTIPOLYGON (((-61.00080 -11.29737, -61.00103... |
| 1100056.0 | 36.757949 | MULTIPOLYGON (((-61.49976 -13.00525, -61.49426... |
| 1100080.0 | 21.820959 | MULTIPOLYGON (((-63.71199 -11.65013, -63.70413... |
| ... | ... | ... |
| 5221809.0 | 97.656250 | MULTIPOLYGON (((-48.10538 -17.28142, -48.10127... |
| 5221908.0 | 52.260256 | MULTIPOLYGON (((-49.69684 -16.94378, -49.69317... |
| 5222005.0 | 14.426892 | MULTIPOLYGON (((-48.38114 -16.63141, -48.38044... |
| 5222054.0 | 11.437722 | MULTIPOLYGON (((-49.84456 -17.58262, -49.84020... |
| 5300108.0 | 25.768854 | MULTIPOLYGON (((-47.41734 -15.54655, -47.41402... |
3828 rows × 2 columns
base = gdf.plot(color='white', edgecolor='black', figsize=(30,30))
base.set_title('Prevalência de Casos de Suicídio no Brasil (2014-2018)', fontsize=20)
gdf.plot(ax=base,column='prevalencia' , legend=True, scheme='percentiles', cmap='OrRd', legend_kwds={'loc': 'upper right'})
/home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/plotting.py:33: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. /home/raquel/anaconda3/lib/python3.9/site-packages/descartes/patch.py:62: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead. /home/raquel/anaconda3/lib/python3.9/site-packages/descartes/patch.py:64: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead. /home/raquel/anaconda3/lib/python3.9/site-packages/geopandas/plotting.py:33: ShapelyDeprecationWarning: Iteration over multi-part geometries is deprecated and will be removed in Shapely 2.0. Use the `geoms` property to access the constituent parts of a multi-part geometry. /home/raquel/anaconda3/lib/python3.9/site-packages/descartes/patch.py:62: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead. /home/raquel/anaconda3/lib/python3.9/site-packages/descartes/patch.py:64: ShapelyDeprecationWarning: The array interface is deprecated and will no longer work in Shapely 2.0. Convert the '.coords' to a numpy array instead.
<AxesSubplot:title={'center':'Prevalência de Casos de Suicídio no Brasil (2014-2018)'}>
NOTA:
Percebe-se a cor mais escura no mapa nas regiões abrangendo o Sul e Sudeste do país, indicando maior prevalência de casos.
Ademais, nota-se um baixo número no Centro-Norte do país (denotados pela cor branca), devendo ser considerado a seguinte questão: De fato ocorrem menos casos de suicídio nessas regiões, ou há subnotificação?